<?php
/**
 * 监控任务 ws http 8811
 * User: xiant_000
 * Date: 2018/11/25
 * Time: 23:14
 */

class Server
{
    const PORT = 8811;

    public function port()
    {
        $shell = 'netstat -tulnp 2>/dev/null|grep ' . self::PORT . ' | grep LISTEN | wc -l';

        $result = shell_exec($shell);
        if ($result != 1) {
            // 发送报警服务 邮件 短信
            // todo alidayu
            echo date("Ymd H:i:s") . PHP_EOL;
        }
    }
}

swoole_timer_tick(2000, function ($timer_id) {
    (new Server())->port();
    echo 'time-start' . PHP_EOL;
});